<?php
include_once("../service/ProductService.php");
/**
 * @author Minh Luan
 * @copyright 2012
 */
if(isset($_GET['n'])){
    $pro_id = $_GET['n'];
    $productInfor = mysql_fetch_array(getProduct($pro_id));
    if(!hasReceipt($pro_id)){
        //Delete Image Files and Image URL in database
        $productUrl = getImageOfProduct($pro_id);
        while($row = mysql_fetch_array($productUrl)){
            if($row["IMG_PATH"] != ""){
                if(unlink("../images/product/PRO_".$pro_id."/".$row["IMG_PATH"])){
                deleteImageUrl($row["IMG_ID"]);        
                }
            }else{
                deleteImageUrl($row["IMG_ID"]);
            }
        }
        //Delete Information
        if(deleteProductInformation($pro_id)){
            echo "<script>location.href='../admin/product.php?msg=1'</script>";    
        }else{
            echo "<script>location.href='../admin/product.php?msg=2'</script>";    
        }
            
    }else{
        echo "<script>location.href='../admin/product.php?msg=3'</script>";
    }
}
?>